<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<fieldset style="width:95%;height:20%;margin-left: 10px">
		<legend>全局缺货提醒</legend>
		<div>
			药品数量：<input id="num1" class="mini-spinner" minValue="1" maxValue="999" />
		</div>
		<div style="text-align:center;padding:15px;">
			<sec:authorize url='/medicine_warn_num_set.do'>
            <a class="mini-button" onclick="onOk();" style="width:80px;">保存设置</a>     
            </sec:authorize>  
        </div>
	</fieldset>
	<fieldset style="width:95%;height:70%;margin-left: 10px">
		<legend>特定货物缺货提醒</legend>
		<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
			<sec:authorize url='/stockout_medicine_warn.do'>
			<a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
			</sec:authorize>
			<sec:authorize url='/stockout_medicine_warn_edit.do'>
			<a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
			</sec:authorize>
			<sec:authorize url='/medicine_del_warn.do'>
	        <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
	        </sec:authorize>
		</div>
		<div class="mini-fit" >
		<div id="datagrid1" class="mini-datagrid" idField="id" pageSize="20" url="medicine_is_warn.do" multiSelect="true" style="width:100%;height:100%;">
			<div property="columns" >
				<div type="indexcolumn"></div>
				<div type="checkcolumn"></div>
				<div field="serialNum" width="25%" headerAlign="center" align="center">药品编号</div>
				<div field="name" width="25%" headerAlign="center" align="center">药品名称</div>
				<div field="unitValue" width="25%" headerAlign="center" align="center">单位</div>
				<div field="warnNum" width="25%" headerAlign="center" align="center">缺货预警数量</div>
			</div>
		</div>
		</div>
	</fieldset>

<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();
$.post("medicine_warn_num.do",function(data){
	mini.get("num1").setValue(data.num);
},"json");
function onOk(){
	var num = mini.get("num1").getValue();
	$.post("medicine_warn_num_set.do",{warnNum:num},function(data){
		if(data.success){
    		mini.showMessageBox({
                title: "提示",
                showModal:false,
                iconCls: "mini-messagebox-info",
                message: "设置成功！",
                timeout: 3000,
                x: 'right',
                y: 'bottom'
            });
    	}
	},"json");
}

function add() {
    mini.open({
        url: "stockout_medicine_warn.do",
        title: "新增药品缺货提醒", width: 500, height: 200,
        allowResize:false,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "保存成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
	            grid.reload();
        	}
        }
    });
}

//批量删除
function remove() {
    var rows = grid.getSelecteds();
    if (rows.length > 0) {
    	mini.confirm("确定删除记录？", "确定？",function (action) {
    		if (action == "ok") {
    			var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var id = ids.join(',');
                grid.loading("操作中，请稍后......");
                $.ajax({
                    url: "medicine_del_warn.do?id=" +id,
                    success: function (text) {
                    		mini.showMessageBox({
        	                    title: "提示",
        	                    showModal:false,
        	                    iconCls: "mini-messagebox-info",
        	                    message: "删除成功！",
        	                    timeout: 3000,
        	                    x: 'right',
        	                    y: 'bottom'
        	                });
                        grid.reload();
                    }
                });
    		}
    	});
    } else {
        mini.alert("请选中一条记录");
    }
}

//修改
function edit() {
    var row = grid.getSelecteds();
    if (row.length == 1) {
        mini.open({
            url: "stockout_medicine_warn_edit.do",
            allowResize:false,
            title: "修改药品缺货提醒", width: 500, height: 200,
            onload: function () {
                var iframe = this.getIFrameEl();
                iframe.contentWindow.SetData(row[0]);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "修改成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
            }
        });
        
    } else {
        mini.alert("请选中一条记录");
    }
    
}
</script>
</body>
</html>